package v2.chapter3.mq.test1;

import java.io.IOException; 
import java.util.Hashtable; 
import com.ibm.mq.MQException; 
import com.ibm.mq.MQMessage; 
import com.ibm.mq.MQPutMessageOptions; 
import com.ibm.mq.MQQueue; 
import com.ibm.mq.MQQueueManager; 

public class MQSample{ 
    //定义队列管理器和队列的名称 
    private static String qmName = "QM_00000000"; 
    private static String qName = "RQ_88888888"; 
    
    private static MQQueueManager qMgr; 
    private static Hashtable properties = new Hashtable(); 
    public static void main(String args[]) { 
        try { 
            properties.put("hostname", "10.1.1.1"); 
            properties.put("port", new Integer(1414)); 
            properties.put("channel", "DC.SVRCONN"); 
            properties.put("CCSID", new Integer(1381)); 
            properties.put("transport","MQSeries");  
            
            qMgr = new MQQueueManager(qmName,properties);  
            int openOptions = 16; 
            
            MQQueue remoteQ = qMgr.accessQueue(qName, openOptions);  
            MQMessage putMessage = new MQMessage(); 
            putMessage.writeUTF("Test");  
            MQPutMessageOptions pmo = new MQPutMessageOptions(); 
       
            remoteQ.put(putMessage,pmo); 
            System.out.println("Message has been input into the Remote Queue"); 
           
            remoteQ.close();  
            qMgr.disconnect(); 
        }catch (MQException ex) {  
            System.out.println("A WebSphere MQ error occurred : Completion code " + ex.completionCode + 
          " Reason code " + ex.reasonCode); 
        }catch (IOException ex) {
            System.out.println("An error occurred whilst writing to the message buffer: " + ex); 
        }catch(Exception ex){ 
            ex.printStackTrace(); 
        } 
    } 
}